﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BaseMono : MonoBehaviour
{
    public void Awake()
    {
        CommonRun(EBaseMonoMethod.Awake);
    }

    public void OnEnable()
    {
        CommonRun(EBaseMonoMethod.OnEnable);
    }

    public void Start()
    {
        CommonRun(EBaseMonoMethod.Start);
    }

    public void FixedUpdate()
    {
        CommonRun(EBaseMonoMethod.FixedUpdate);
    }

    public void Update()
    {
        CommonRun(EBaseMonoMethod.Update);
    }

    public void OnDisable()
    {
        CommonRun(EBaseMonoMethod.OnDisable);
    }

    public void OnDestroy()
    {
        CommonRun(EBaseMonoMethod.OnDestroy);
    }
    
    private void CommonRun(EBaseMonoMethod m)
    {
        switch (m)
        {
            case EBaseMonoMethod.Awake:
                MoAwake();
                break;
            case EBaseMonoMethod.OnEnable:
                MoEnable();
                break;
            case EBaseMonoMethod.Start:
                MoStart();
                break;
            case EBaseMonoMethod.FixedUpdate:
                MoFixedUpdate(); 
                break;
            case EBaseMonoMethod.Update:
                MoUpdate();
                break;
            case EBaseMonoMethod.OnDisable:
                MoDisable();
                break;
            case EBaseMonoMethod.OnDestroy:
                MoDestroy();
                break;
            default:
                PLDebug.LogError("错误: " + this.gameObject.name + " " + m);
                break;
        }
    }

    protected virtual void MoAwake() { }
    protected virtual void MoEnable() { }
    protected virtual void MoStart() { }
    protected virtual void MoFixedUpdate() { }
    protected virtual void MoUpdate() { }
    protected virtual void MoDisable() { }
    protected virtual void MoDestroy() { }

}

public enum EBaseMonoMethod
{
    Awake,
    OnEnable,
    Start,
    FixedUpdate,
    Update,
    OnDisable,
    OnDestroy
}
